package com.mitcub.panda.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mitcub.panda.base.BaseQuery;
import com.mitcub.panda.base.BaseServiceImpl;
import com.mitcub.panda.entity.Goods;
import com.mitcub.panda.mapper.GoodsMapper;
import com.mitcub.panda.query.GoodsQuery;
import com.mitcub.panda.service.IGoodsService;
import com.mitcub.panda.utils.RespResult;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @项目名称: panda
 * @类名称: GoodsServiceImpl
 * @类描述: 商品 服务实现类
 * @作者: tangloong
 * @创建时间: 2021/11/13 17:22
 */
@Service
public class GoodsServiceImpl extends BaseServiceImpl<GoodsMapper, Goods> implements IGoodsService {

    @Resource
    private GoodsMapper goodsMapper;

    /**
     * 获取数据列表
     * @param query 查询条件
     * @return
     */
    @Override
    public RespResult getList(BaseQuery query) {
        GoodsQuery memberQuery = (GoodsQuery) query;
        // 查询条件
        QueryWrapper<Goods> queryWrapper = new QueryWrapper<>();

        // 状态：1正常 2禁用
        if (memberQuery.getStatus() != null) {
            queryWrapper.eq("status", memberQuery.getStatus());
        }
        queryWrapper.eq("mark", 1);
        queryWrapper.orderByDesc("id");

        // 查询数据
        Page<Goods> page = new Page<>(memberQuery.getPage(), memberQuery.getLimit());
        IPage<Goods> data = goodsMapper.selectPage(page, queryWrapper);
        return RespResult.success("操作成功", data.getRecords(),data.getTotal());
    }

}